" join all lines of shell commands into one line and copy to system clipboard
function! JoinAllLinesFunction()
  " wrapping is evil
  set nowrap
  " join excessively
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
  normal J
endfunction

function! JoinShellLinesFunction()
  " wrapping is evil
  set nowrap
  " stop auto line wrapping
  setlocal formatoptions-=c formatoptions-=o formatoptions-=r
  " append semicollon to the eol
  %normal A;
  " back to top
  0
  " join all lines silently
  silent! call JoinAllLinesFunction()
  " copy to system clipboard
  normal V"+y
  " quit!
  q!
endfunction

command! JoinShellLines call JoinShellLinesFunction()

if !empty($ENV_MAC)
  " convert all files in the current directory into mp3 files
  function! ConvertAllFilesIntoMp3Function()
    " wrapping is evil
    set nowrap
    " load all file names
    r! ls
    " remove empty line
    v/./d
    " stop auto wrapping
    setlocal formatoptions-=c formatoptions-=o formatoptions-=r
    " format each line
    %normal I'jlA'jl0y$A jl$pIffmpeg -i jl$T.cemp3jl
    " finish it off
    JoinShellLines
  endfunction

  command! ConvertAllFilesIntoMp3 silent! call ConvertAllFilesIntoMp3Function()
endif
